

data_path = '危化品&整治敏感词库.csv'
new_data_paht = "new_"+data_path


import csv



ignore_word = []
with open(new_data_paht,'w',encoding='utf-8') as fwrite:
    with open(data_path,'r',encoding='utf-8') as fread:
        all_lines = csv.reader(fread)
        for index,lines in enumerate(all_lines):
            if index == 0:
                fwrite.write(",".join(lines))
            else:


                if "!" in lines[0]:
                    tokens = lines[0].split("!")
                    lines[0] = tokens[0]
                    ignore_word.extend(tokens[1:])
                elif "-" in lines[0]:
                    tokens = lines[0].split("-")
                    lines[0] = tokens[-1]

                fwrite.write(",".join(lines) + "\n")


with open('ignore_word.csv',encoding='utf-8',mode='w') as fwrite:
    fwrite.write("ignore_word")
    for word in ignore_word:
        fwrite.write(word + "\n")